input1 = input("please input a string\n")
input2 = input("please input a string\n")
maxStr = []
i,j = 0,0

for i in range(0,len(input1)-1):
    j = 0
    for j in range(j+1,len(input1)):
        if input1[i:j] in input2:
            maxStr.append(input1[i:j])

if maxStr != []:
    print(max(maxStr))
else:
    print('-1')
